<!--suppress ALL -->
<script src="/assets/backend/static/jquery.upload.js"></script>

<form id="category_category_edit_dialog_form" method="post">
    <table width="100%" class="mdoutable">
        <tr>
            <td width="130">上级栏目：</td>
            <td><input id="category_category_edit_dialog_form_parentid" name="parentid" class="easyui-combotree"
                       value="{{ .category.Parentid }}"/></td>
        </tr>
        <tr>
            <td>栏目名称：</td>
            <td><input name="catname" value="{{.category.Catname}}" type="text" class="easyui-textbox"
                       data-options="required: true"/></td>
        </tr>
        <tr>
            <td>栏目类型：</td>
            <td>
                <select id="category_category_edit_dialog_form_type"
                        name="type"
                        class="easyui-combobox"
                        data-options="editable:false,panelHeight:'auto',onChange:categoryCategoryEditDialogFormTypeChange"
                        style="width:80px"
                        disabled>
                    {{range $i,$v := .typelist}}{{if eq $.category.Type $i}}
                        <option value="{{$i}}" selected>{{$v}}</option>
                    {{else}}
                        <option value="{{$i}}">{{$v}}</option>
                    {{end}}{{end}}
                </select>
                <span style="color:gray;padding-left:15px">设置后不可修改</span>
            </td>
        </tr>
        <tr>
            <td>缩略图：</td>
            <td>
                {{.thumbHtml}}
            </td>
        </tr>
        <tr id="category_category_edit_dialog_form_url" {{if ne .category.Type 2}}style="display:none" {{end}}>
            <td>链接：</td>
            <td><input name="url" value="{{.category.Url}}" class="easyui-textbox" type="text"></td>
        </tr>

        <tr {{if eq .category.Type 2}} style="display: none" {{end}}>
            <td>栏目目录：</td>
            <td><input name="dir" class="easyui-textbox" value="{{.category.Dir}}" type="text"/></td>
        </tr>

        <tr class="category_category_dir_opt stpl" {{if ne .category.Type 0}} style="display: none" {{end}}>
            <td>列表页面</td>
            <td colspan="2"><input class="easyui-combotreegrid" name="list_tpl" value="{{.category.ListTpl}}" data-options="
					method:'get',
					width: 500,
					panelWidth:750,
					url:'/public/fedir-scan',
					idField: 'id',
					treeField:'name',
					columns:[[
						{field:'name',title:'Name',width:550},
					]]"></td>
        </tr>

        <tr class="category_category_dir_opt" {{if eq .category.Type 2}} style="display: none" {{end}}>
            <td>详情页面</td>
            <td colspan="2"><input class="easyui-combotreegrid" name="detail_tpl" value="{{.category.DetailTpl}}" data-options="
					method:'get',
					width: 500,
					panelWidth:750,
					url:'/public/fedir-scan',
					idField: 'id',
					treeField:'name',
					columns:[[
						{field:'name',title:'Name',width:550},
					]]"></td>
        </tr>

        <tr>
            <td>关键字：</td>
            <td><input name="keywords" value="{{.category.Keywords}}" class="easyui-textbox" type="text"></td>
        </tr>

        <tr>
            <td>描述：</td>
            <td><textarea name="description"
                          style="width:100%;height:60px">{{.category.Description}}</textarea></td>
        </tr>
        <tr>
            <td>是否启用：</td>
            <td>
                <input name="ismenu" class="easyui-switchbutton" {{if eq .category.Ismenu 1}}checked{{end}}
                       data-options="onText:'是',offText:'否'">
            </td>
        </tr>
    </table>
</form>


<script type="text/javascript">
    $('#category_category_edit_dialog_form_parentid').combotree({url: "/b/category/category-select"});

    function categoryCategoryAddDialogFormSubmit() {
        var f = $("#category_category_edit_dialog_form");
        f.form({
            method: "post",
            url: "/b/category/category-edit?id={{ .category.Catid }}",
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (res) {
                res = JSON.parse(res)
                if (res.errcode) {
                    $.messager.alert('提示信息', res.errmsg, 'error');
                } else {
                    $.messager.alert('提示信息', res.errmsg, 'info');
                    $('#category_category_edit_dialog').dialog('close');
                    categoryCategoryListRefresh();
                }
            }
        });
        f.submit();
    }

    function categoryCategoryEditDialogFormTypeChange(val) {
        var category_category_edit_dialog_form_url = $('#category_category_edit_dialog_form_url');
        if (val === parseInt('2')) {
            category_category_edit_dialog_form_url.show();
        } else {
            category_category_edit_dialog_form_url.val('');
            category_category_edit_dialog_form_url.hide();
        }
    }

    $('#content_edit_news_form_thumb_input').click(function (e) {
        e.preventDefault();
        $.upload({
            url: "/public/upload",
            fileName: 'filedata',
            params: {},
            dataType: 'json',
            onSend: function () {
                return true;
            },
            onComplate: function (data) {
                if (0 === Number(data.errcode)) {
                    $('#content_edit_news_form_thumb_input').attr('src', data.url);
                    $('#content_edit_news_form_thumb_input').next('input:hidden').val(data.url);
                } else {
                    $.messager.alert('提示信息', data.errmsg, 'error');
                }
            }
        });
        return false;
    });
</script>
